@extends('layout.adminlayout')
@section('css')
<script src="/admin/js/metisMenu.min.js"></script>
<script src="/admin/js/custom.js"></script>
<link href="/admin/css/area_info.css" rel="stylesheet">
<link href="/admin/css/custom.css" rel="stylesheet">
<link href="/admin/css/add_manage.css" rel="stylesheet">
<link href="/admin/css/select_building.css" rel="stylesheet">
@endsection
@section('content')
<div class="forms">
	<div class=" form-grids row form-grids-right">
		<div class="widget-shadow " data-example-id="basic-forms"> 
			<div class="form-title">
				<h4>添加位置 :</h4>
			</div>
			<div class="form-body">
				<form action="/admin/building/store" method="post" class="form-horizontal" onsubmit="return fun4()">
					{{csrf_field()}}
					<div class="form-group">
						<label for="inputEmail3" class="col-sm-2 control-label">
							所属区域 :
						</label>
						<li class="area_info">
							<div class="col-sm-6">
								<select name="area" id="area" class="form-control1">
									<option value="0">请选择区域</option>
									@if($area != null)
										@foreach($area as $v)
											<option value="{{$v['a_id']}}">{{$v['a_name']}}</option>
										@endforeach
									@endif
								</select>
							</div>
						</li>
					</div>
					<div class="form-group">
						<label for="inputEmail3" class="col-sm-2 control-label">
							所属建筑 :
						</label>
						<li class="area_info">
							<div class="col-sm-6">
								<input type="text" name="buildings" class="form-control" value="" placeholder="请选择">
								<input type="hidden" name="building" class="form-control" value="" placeholder="请选择">
								<dl class="col-sm-6 dv4" id="building">
								</dl>
							</div>
						</li>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-2 control-label">
							位置名称 :
						</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" name="room" id="room" placeholder="位置名称">
						</div>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-2 control-label">
							所在楼层 :
						</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" name="floor" id="floor" placeholder="所在楼层">
						</div>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-2 control-label">

						</label>
						<ul id="ul">
						</ul>
					</div>
					<div class="form-group">
						<label for="inputPassword3" class="col-sm-2 control-label">
							负责人 :
						</label>
						<div class="col-sm-6">
							<input type="text" class="form-control" name="manage" placeholder="管理员名称" id="manage" style="width: 87%; float: left">
							<button type="button" class="btn btn-default" id="add" style="float: right">添加</button>
						</div>
					</div>
					<div class="col-sm-offset-2">
						<button type="button" class="btn btn-default" id="sub" style="margin-left: 0.4rem;">提交</button>
					</div>
				</form> 
			</div>
		</div>
	</div>
</div>
<script>
	//区域建筑联动
	$('#area').change(function () {
		var areaId = $('#area').val();
		var dd = '<option class="dstyle" value="">请选择</option>';
		$.ajax({
			type:'post',
			url:'/admin/room/getbuild',
            async:false,
            data:{
                "_token": $("input[name=_token]").val(),
                'areaId':areaId,
            },
            dataType:'json',
            success:function (data) {
                for(var i=0;i<data.length;i++){
                    dd += '<option class="dstyle" value="'+data[i]['b_id']+'">'+data[i]['b_name']+'</option>';
				}
                $('#building').empty();
                $('#building').append(dd);
            }
		})
    })
    //提交表单
    $('#sub').click(function () {
        var area = $('#area').val();
        var building = $('input[name=building]').val();
        var room = $('#room').val();
        var floor = $('#floor').val();
        var manage = new Array();
        $('.mng').each(function () {
            manage.push($(this).html());
        });
        if(area != 0 && building != 0 && room != '' && floor != ''){
            $.ajax({
                type:'post',
                url:'/admin/room/create',
                async:false,
                data:{
                    "_token": $("input[name=_token]").val(),
                    'area':area,
					'building':building,
					'room':room,
					'floor':floor,
                    'manage':manage
                },
                dataType:'json',
                success:function (data) {
                    if(data.status == '1'){
                        location.href = '/admin/room/index';
                    }
                    return false;
                }
            })
        }else{
            alert('信息填写不完整')
            return false;
        }
    });
</script>
@endsection
@section('lastjs')
<script src="/admin/js/add_manage.js"></script>
<script src="/admin/js/select_building.js"></script>
@endsection